﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using BCDto.TMS.MallInterface.MallGoodsFreight;
using BCService.TMS.MallInterface.MallGoodsFreight;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;

namespace BCTMSRESTful.Controllers.Management.TMS.MallInterface
{
    /// <summary>
    /// 商城商品运费接口
    /// </summary> 
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class MallGoodsFreightController : ManagementBaseController
    {
        #region var
        private IMallGoodsFreightService mallGoodsFreightService;
        #endregion


        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary> 
        public MallGoodsFreightController(IMallGoodsFreightService mallGoodsFreightService)
        {
            this.mallGoodsFreightService = mallGoodsFreightService;
        }
        #endregion

        #region POST 添加  
        /// <summary>
        /// 添加新商城商品运费纪录
        /// </summary>
        /// <param name="dto">商城商品运费数据模型</param>
        /// <returns></returns>
        [Log("添加新商城商品运费纪录")]
        [HttpPost]
        [ProducesResponseType(typeof(MallGoodsFreightRequestDto), 200)]
        public IActionResult Post([FromBody] MallGoodsFreightRequestDto dto)
        {
            var a = mallGoodsFreightService.Add(dto, this.Admin);
            return Ok(a);
        }

        #endregion

        #region PUT 修改   
        /// <summary>
        /// 修改商城商品运费纪录
        /// </summary>
        /// <param name="dto">商城商品运费数据模型</param>
        /// <returns></returns>
        [Log("修改商城商品运费纪录")]
        [HttpPut]
        [ProducesResponseType(typeof(MallGoodsFreightDto), 200)]
        public IActionResult Put([FromBody] MallGoodsFreightDto dto)
        {
            var a = Ok(mallGoodsFreightService.Update(dto, this.Admin));
            return a;
        }
        #endregion

        #region 删除  
        /// <summary>
        /// 删除商城商品运费纪录
        /// </summary>
        /// <param name="mallGoodsFreightId">商城商品运费ID</param>
        /// <returns></returns>
        [Log("删除商城商品运费纪录")]
        [HttpDelete("{mall_goods_freight_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "mall_goods_freight_id")] long mallGoodsFreightId)
        {
            mallGoodsFreightService.Delete(mallGoodsFreightId);
            return NoContent();
        }
        #endregion

        #region GetByID     
        /// <summary>
        /// 获取一条商城商品运费纪录
        /// </summary>
        /// <param name="mallGoodsFreightId">商城商品运费ID</param>
        /// <returns></returns>
        [HttpGet("{mall_goods_freight_id}")]
        [ProducesResponseType(typeof(MallGoodsFreightDto), 200)]
        public IActionResult Get([FromRoute(Name = "mall_goods_freight_id")] long mallGoodsFreightId)
        {
            return (Ok(mallGoodsFreightService.GetById(mallGoodsFreightId)));

        }
        #endregion

        #region Query 
        /// <summary>
        /// 查询商城商品运费记录 -- 分页
        /// </summary>
        /// <param name="mallShopNo">商城商户编号</param>
        /// <param name="goodsSource">商品来源（商城/仓库）</param>
        /// <param name="transportBusinessType">业务类型（同城/小件）</param>
        /// <param name="freightType">配送方式（急速/快运/一般）</param>
        /// <param name="goodsSku">商品SKU</param>
        /// <param name="goodsName">商品名称</param>
        /// <param name="goodsWeight">商品重量</param>
        /// <param name="goodsVolume">商品体积</param>
        /// <param name="goodsLength">商品长度</param>
        /// <param name="goodsWidth">商品宽度</param>
        /// <param name="goodsHeight">商品高度</param>
        /// <param name="goodsCount">商品数量</param>
        /// <param name="goodsPrice">商品单价</param>
        /// <param name="goodsUnit">商品单位</param>
        /// <param name="isMonthPay">月结</param>
        /// <param name="startPrice">起步价</param>
        /// <param name="startMileage">起步里程</param>
        /// <param name="everyMileagePrice">续l里程价格</param>
        /// <param name="provinceCode">省份编码</param>
        /// <param name="cityCode">城市编码</param>
        /// <param name="countyCode">区县编码</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页记录数</param>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<MallGoodsFreightDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "mall_shop_no")] string mallShopNo,
            [FromQuery(Name = "goods_source")] string goodsSource,
            [FromQuery(Name = "transport_business_type")] string transportBusinessType,
            [FromQuery(Name = "freight_type")] string freightType,
            [FromQuery(Name = "goods_sku")] string goodsSku,
            [FromQuery(Name = "goods_name")] string goodsName,
            [FromQuery(Name = "goods_unit")] string goodsUnit,
            [FromQuery(Name = "goods_weight")] decimal? goodsWeight,
            [FromQuery(Name = "goods_volume")] decimal? goodsVolume,
            [FromQuery(Name = "goods_length")] decimal? goodsLength,
            [FromQuery(Name = "goods_width")] decimal? goodsWidth,
            [FromQuery(Name = "goods_height")] decimal? goodsHeight,
            [FromQuery(Name = "goods_count")] int? goodsCount,
            [FromQuery(Name = "goods_price")] decimal? goodsPrice,
            [FromQuery(Name = "is_month_pay")] bool? isMonthPay,
            [FromQuery(Name = "start_price")] decimal? startPrice,
            [FromQuery(Name = "start_mileage")] int? startMileage,
            [FromQuery(Name = "every_mileage_price")] decimal? everyMileagePrice,
            [FromQuery(Name = "province_code")] string provinceCode,
            [FromQuery(Name = "city_code")] string cityCode,
            [FromQuery(Name = "county_code")] string countyCode,
            [FromQuery(Name = "index")] int? pageIndex = 1, 
            [FromQuery(Name = "size")] int? pageSize = 10)
        {
            var a = Ok(mallGoodsFreightService.GetList(mallShopNo, goodsSource, transportBusinessType, freightType, goodsSku, goodsName, goodsWeight, goodsVolume, goodsLength, goodsWidth, goodsHeight, goodsCount, goodsPrice, goodsUnit, isMonthPay, startPrice, startMileage, everyMileagePrice, provinceCode, cityCode, countyCode, pageIndex.Value, pageSize.Value));
            return a;
        }
        #endregion
    }

}
